<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\BaseController;
use Illuminate\Http\Request;

class SmsController extends BaseController
{
    public $validate = [
        "send" => ["rules" => [
            "sms_template" => "required|integer|max:100",
            "phone" => "sometimes|required|phone",
        ]],
    ];

    /**
     * @path /sms/send
     * @category 短信
     * @title 发送
     * @method POST
     * @params [{"name":"phone","type":"text","required":1,"example":"","desc":"手机号"},{"name":"sms_template","type":"text","required":1,"example":"","desc":"看备注"}]
     * @resBody {"success":true,"statusCode":200,"result":true,"message":"OK"}
     * @description 1.【前端】template文档：https://thoughts.teambition.com/workspaces/5e23ee5e8d0a96001ac16c9e/docs/5f8d34e6e6eed500018bc105
     */
    public function send(Request $request)
    {
        $params = $request->all();
        if (!array_key_exists('phone', $params)) {
            $params['phone'] = $this->user->phone ?? '';
        }

        $data = service()->SmsService->sendSms($params['phone'], $params['sms_template']);

        return $this->apiReturn($data);
    }
}
